package com.igl.talk.android.client.ide.activities;/*
 * @author Adam Wieczorek 
 *
 * 21/04/2014
 *
 * All rights reserved.
 */

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.igl.talk.android.client.application.BaseApplication;
import com.igl.talk.android.client.core.service.Server;
import com.igl.talk.android.client.core.service.ServerApi;
import com.igl.talk.android.client.core.service.ServiceManager;

public class BaseServiceBindingActivity extends Activity {

    private static final String LOG_TAG = BaseServiceBindingActivity.class.getSimpleName() + ".class";

    protected ServiceManager serviceManager;

    protected final ServerApi serverService = Server.INSTANCE;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        serviceManager = ((BaseApplication) this.getApplicationContext()).getServiceManager();
    }

    @Override
    protected void onPause() {
        Log.d(LOG_TAG, "Pausing activity and unbinding service.");
        super.onPause();
        serviceManager.unbindService(serverService.getConnection());
    }

    @Override
    protected void onResume() {
        Log.d(LOG_TAG, "Resuming activity and binding service.");
        super.onResume();
        serviceManager.bindService(serverService.getConnection());
    }

    @Override
    protected void onDestroy() {
        Log.d(LOG_TAG, "Destroying activity and stopping service.");
        super.onDestroy();
        serviceManager.stopService();
    }

    public void exit() {
        super.onBackPressed();
    }
}
